<template>
  <!-- 点餐方式选择弹窗 -->
  <view class="modal" v-if="visible">
    <view class="modal-mask"></view>
    <view class="modal-content">
      <view class="modal-title">请选择点餐方式</view>
      <view class="mode-options">
        <view class="mode-item" @click="handleScanCode">
          <image src="/static/member/scan.png" mode="aspectFit" class="mode-icon"></image>
          <text>扫码点餐</text>
        </view>
        <view class="mode-item" @click="selectMode('takeout')">
          <image src="/static/member/takeout.png" mode="aspectFit" class="mode-icon"></image>
          <text>外卖点餐</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { boardApi } from '../api/index'

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const emit = defineEmits(['select'])

// 处理扫码
const handleScanCode = () => {
  uni.scanCode({
    success: async (res) => {
      const board = await boardApi.getBoardById(res.result)
      console.log('扫码结果：', board)
      emit('select', {
        mode: 'scan',
        board: board
      })
    },
    fail: (err) => {
      console.error('扫码失败：', err)
      uni.showToast({
        title: '扫码失败',
        icon: 'none'
      })
    }
  })
}

// 选择外卖模式
const selectMode = (mode) => {
  emit('select', {
    mode: mode,
    board: null
  })
}
</script>

<style lang="scss" scoped>
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-mask {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  width: 80%;
  max-width: 600rpx;
  background: #fff;
  border-radius: 20rpx;
  padding: 40rpx 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}

.modal-title {
  text-align: center;
  font-size: 32rpx;
  font-weight: bold;
  margin-bottom: 40rpx;
  color: #333;
}

.mode-options {
  display: flex;
  justify-content: space-around;
  padding: 20rpx 0;
}

.mode-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20rpx;
  border-radius: 12rpx;
  background: #f8f8f8;
  width: 200rpx;
  transition: all 0.3s;

  &:active {
    transform: scale(0.95);
    background: #f0f0f0;
  }
}

.mode-icon {
  width: 80rpx;
  height: 80rpx;
  margin-bottom: 16rpx;
}

.mode-item text {
  font-size: 28rpx;
  color: #333;
}
</style> 